// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   OrderDetailScrPanel.java

package com.boci.clientapp.orderstatus;

import com.boci.clientapp.main.ClientAppLoader;
import com.boci.clientapp.orderstatus.action.OrderDetailAction;
import com.boci.clientapp.orderstatus.vo.FilledOrderVO;
import com.boci.clientapp.orderstatus.vo.OrderDetailVO;
import com.boci.common.constant.ClientAppConst;
import com.boci.common.ui.AbstractPanel;
import com.boci.common.ui.control.CMTableModel;
import com.boci.common.ui.control.StringRenderer;
import com.boci.common.util.*;
import com.boci.common.vo.ResponseVO;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.*;

public class OrderDetailScrPanel extends AbstractPanel
    implements TableModelListener
{

    public OrderDetailScrPanel(Locale pLocale, String pModuleName, String pScreenName)
    {
        super(pLocale, pScreenName, pScreenName);
        msgConf = ClientAppLoader.getMessagesConfigurator();
        initGUI();
        setText(pLocale);
    }

    public void setText(Locale pLocale)
    {
        super.setText(pLocale);
        setFont(pLocale);
        currentLocale = pLocale;
        lblStatus.setText(msgConf.getUIMessages("ORDER_STATUS.STATUS", pLocale));
        lblReference.setText(msgConf.getUIMessages("ORDER_STATUS.REFERENCE_NO", pLocale));
        lblPalceOn.setText(msgConf.getUIMessages("ORDER_STATUS.PLACED_ON", pLocale));
        lblDuration.setText(msgConf.getUIMessages("ORDER_STATUS.DURATION", pLocale));
        lblOrderType.setText(msgConf.getUIMessages("ORDER_STATUS.ORDER_TYPE", pLocale));
        lblPrice.setText(msgConf.getUIMessages("ORDER_STATUS.PRICE", pLocale));
        lblQuantity.setText(msgConf.getUIMessages("ORDER_STATUS.QUANTITY", pLocale));
        lblTransaction.setText(msgConf.getUIMessages("ORDER_STATUS.TRANSACTION", pLocale));
        lblSecurityCode.setText(msgConf.getUIMessages("ORDER_STATUS.CODE", pLocale));
        lblNameOfSecurity.setText(msgConf.getUIMessages("ORDER_STATUS.NAME", pLocale));
        lbltitle.setText(msgConf.getUIMessages("ORDER_STATUS.ORDER_DETAILS", pLocale));
        btnBack.setText(msgConf.getUIMessages("ORDER_STATUS.BACK_TO_ORDER_STATUS", pLocale));
        lblFilledOrderDetails.setText(msgConf.getUIMessages("ORDER_STATUS.FILLED_ORDER_DETAILS", pLocale));
        lblFilledQty.setText(msgConf.getUIMessages("ORDER_STATUS.TOTAL_EXECUTED_QUANTITY", pLocale));
        tmFilledOrder.removeTableModelListener(this);
        String columnNames[] = {
            msgConf.getUIMessages("ORDER_STATUS.COL_FILLED_QTY", currentLocale), msgConf.getUIMessages("ORDER_STATUS.COL_FILLED_PRICE", currentLocale)
        };
        tmFilledOrder.setColumnName(columnNames);
        tmFilledOrder.fireTableStructureChanged();
        for(int i = 0; i < tblFilledOrder.getColumnCount(); i++)
        {
            TableColumn column = tblFilledOrder.getColumnModel().getColumn(i);
            column.setCellRenderer(numericRenderer);
        }

        tmFilledOrder.addTableModelListener(this);
        refresh(orderDetailVO);
    }

    private void setFont(Locale pLocale)
    {
        lbltitle.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblStatus.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblReference.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblPalceOn.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblDuration.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblOrderType.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblPrice.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblQuantity.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblTransaction.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblSecurityCode.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblNameOfSecurity.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblFilledOrderDetails.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblFilledQty.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblStatusValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblReferenceValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblPlaceOnValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblDurationValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblOrderTypeValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblPriceValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblQualityValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblTransactionValue.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblSecurityCodeValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblNameOfSecurityValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        lblFilledQtyValue.setFont(ClientAppLoader.getLargePlainTextFont(pLocale));
        btnBack.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
        tblFilledOrder.getTableHeader().setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        numericRenderer.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
    }

    public void initGUI()
    {
        tblFilledOrder = new JTable();
        tmFilledOrder = new CMTableModel();
        tblFilledOrder.setModel(tmFilledOrder);
        tblFilledOrder.getTableHeader().setReorderingAllowed(false);
        tmFilledOrder.addTableModelListener(this);
        orderDetailScrollPane = new JScrollPane();
        orderDetailScrollPane.setViewportView(tblFilledOrder);
        orderDetailScrollPane.getViewport().setOpaque(false);
        orderDetailScrollPane.setOpaque(false);
        orderDetailScrollPane.setBorder(new EtchedBorder(1));
        orderDetailScrollPane.setBackground(Color.WHITE);
        orderDetailScrollPane.setBounds(335, 43, 325, 110);
        add(orderDetailScrollPane);
        numericRenderer = new StringRenderer();
        numericRenderer.setHorizontalAlignment(4);
        setPreferredSize(new Dimension(710, 218));
        setBackground(Color.WHITE);
        setLayout(null);
        int intYPosDiff = 18;
        int intYPos = 22;
        lblNameOfSecurity = new JLabel();
        lblNameOfSecurity.setHorizontalAlignment(4);
        lblNameOfSecurity.setBounds(10, intYPos, 120, 20);
        add(lblNameOfSecurity);
        lblNameOfSecurityValue = new JLabel();
        lblNameOfSecurityValue.setBounds(145, intYPos, 320, 20);
        add(lblNameOfSecurityValue);
        intYPos += intYPosDiff;
        lblSecurityCodeValue = new JLabel();
        lblSecurityCodeValue.setBounds(145, intYPos, 160, 20);
        add(lblSecurityCodeValue);
        lblSecurityCode = new JLabel();
        lblSecurityCode.setHorizontalAlignment(4);
        lblSecurityCode.setBounds(10, intYPos, 120, 20);
        add(lblSecurityCode);
        intYPos += intYPosDiff;
        lblTransaction = new JLabel();
        lblTransaction.setHorizontalAlignment(4);
        lblTransaction.setBounds(10, intYPos, 120, 20);
        add(lblTransaction);
        lblTransactionValue = new JLabel();
        lblTransactionValue.setForeground(Color.BLUE);
        lblTransactionValue.setBounds(145, intYPos, 160, 20);
        add(lblTransactionValue);
        intYPos += intYPosDiff;
        lblQualityValue = new JLabel();
        lblQualityValue.setBounds(145, intYPos, 160, 20);
        add(lblQualityValue);
        lblQuantity = new JLabel();
        lblQuantity.setHorizontalAlignment(4);
        lblQuantity.setBounds(10, intYPos, 120, 20);
        add(lblQuantity);
        intYPos += intYPosDiff;
        lblPrice = new JLabel();
        lblPrice.setHorizontalAlignment(4);
        lblPrice.setBounds(10, intYPos, 120, 20);
        add(lblPrice);
        lblPriceValue = new JLabel();
        lblPriceValue.setBounds(145, intYPos, 160, 20);
        add(lblPriceValue);
        intYPos += intYPosDiff;
        lblOrderTypeValue = new JLabel();
        lblOrderTypeValue.setBounds(145, intYPos, 160, 20);
        add(lblOrderTypeValue);
        lblOrderType = new JLabel();
        lblOrderType.setHorizontalAlignment(4);
        lblOrderType.setBounds(10, intYPos, 120, 20);
        add(lblOrderType);
        intYPos += intYPosDiff;
        lblDuration = new JLabel();
        lblDuration.setHorizontalAlignment(4);
        lblDuration.setBounds(10, intYPos, 120, 20);
        add(lblDuration);
        lblDurationValue = new JLabel();
        lblDurationValue.setBounds(145, intYPos, 160, 20);
        add(lblDurationValue);
        intYPos += intYPosDiff;
        lblPlaceOnValue = new JLabel();
        lblPlaceOnValue.setBounds(145, intYPos, 160, 20);
        add(lblPlaceOnValue);
        lblPalceOn = new JLabel();
        lblPalceOn.setHorizontalAlignment(4);
        lblPalceOn.setBounds(10, intYPos, 120, 20);
        add(lblPalceOn);
        intYPos += intYPosDiff;
        lblReference = new JLabel();
        lblReference.setHorizontalAlignment(4);
        lblReference.setBounds(10, intYPos, 120, 20);
        add(lblReference);
        lblReferenceValue = new JLabel();
        lblReferenceValue.setBounds(145, intYPos, 160, 20);
        add(lblReferenceValue);
        intYPos += intYPosDiff;
        lblStatusValue = new JLabel();
        lblStatusValue.setBounds(145, intYPos, 250, 20);
        add(lblStatusValue);
        lblStatus = new JLabel();
        lblStatus.setHorizontalAlignment(4);
        lblStatus.setBounds(10, intYPos, 120, 20);
        add(lblStatus);
        lbltitle = new JLabel();
        lbltitle.setBounds(13, 1, 125, 20);
        add(lbltitle);
        lblFilledOrderDetails = new JLabel();
        lblFilledOrderDetails.setBounds(435, 20, 125, 20);
        lblFilledOrderDetails.setHorizontalAlignment(0);
        add(lblFilledOrderDetails);
        lblFilledQty = new JLabel();
        lblFilledQty.setBounds(335, 153, 170, 20);
        add(lblFilledQty);
        lblFilledQtyValue = new JLabel();
        lblFilledQtyValue.setBounds(520, 153, 125, 20);
        add(lblFilledQtyValue);
        btnBack = new JButton();
        btnBack.setMargin(new Insets(2, 2, 2, 2));
        btnBack.setBounds(440, 175, 130, 25);
        btnBack.setActionCommand("BACK_TO_ORDER_STATUS");
        btnBack.addActionListener(this);
        add(btnBack);
    }

    public void actionPerformed(ActionEvent e)
    {
        PerformanceLogger.startAppTimer();
        String strActionType = e.getActionCommand();
        OrderDetailAction orderDetailAction = new OrderDetailAction();
        orderDetailAction.doProcess(getInputValue(strActionType), strActionType);
        PerformanceLogger.stopAppTimer();
        PerformanceLogger.doLog((new StringBuilder()).append(getScreenName()).append(".").append(strActionType).toString());
    }

    public void refresh()
    {
        SwingUtilities.invokeLater(new Runnable() {

            public void run()
            {
                btnBack.requestFocus();
            }
        }
);
    }

    public void refresh(ResponseVO pResponseVO)
    {
        if(pResponseVO == null)
        {
            lblStatusValue.setText("");
            lblReferenceValue.setText("");
            lblPlaceOnValue.setText("");
            lblDurationValue.setText("");
            lblOrderTypeValue.setText("");
            lblPriceValue.setText("");
            lblQualityValue.setText("");
            lblTransactionValue.setText("");
            lblSecurityCodeValue.setText("");
            lblNameOfSecurityValue.setText("");
            lblFilledQtyValue.setText("");
        } else
        if(pResponseVO instanceof OrderDetailVO)
        {
            orderDetailVO = (OrderDetailVO)pResponseVO;
            String strOrderStatusKey = (new StringBuilder()).append("ORDER_STATUS.").append(orderDetailVO.getOrderStatus()).toString();
            String strOrderStatusValue = msgConf.getUIMessages(strOrderStatusKey, currentLocale);
            if(strOrderStatusValue.equals(strOrderStatusKey))
                lblStatusValue.setText(orderDetailVO.getOrderStatus());
            else
                lblStatusValue.setText(strOrderStatusValue);
            lblReferenceValue.setText(StringUtil.getReferenceNo(orderDetailVO.getOrderId()));
            String strPlaceOnDate = orderDetailVO.getPlacementDate();
            strPlaceOnDate = StringUtil.formatLastUpdatedDateTime(orderDetailVO.getPlacementDate());
            strPlaceOnDate = strPlaceOnDate != null ? strPlaceOnDate : "";
            lblPlaceOnValue.setText(strPlaceOnDate);
            lblDurationValue.setText(msgConf.getUIMessages(orderDetailVO.getOrderDuration(), currentLocale));
            lblOrderTypeValue.setText(msgConf.getUIMessages(orderDetailVO.getOrderType(), currentLocale));
            String strCcy = msgConf.getUIMessages(orderDetailVO.getCurrency(), currentLocale);
            String strPrice = StringUtil.formatPriceValue(orderDetailVO.getPrice(), strCcy);
            String strTempQty = orderDetailVO.getOrderQuantity();
            if(strTempQty == null || strTempQty.length() == 0)
                strTempQty = orderDetailVO.getOriginalQuantity();
            String strQty = StringUtil.formatQtyValue(strTempQty);
            String strNoPriceTypes[] = ClientAppLoader.getNoPriceOrdTypes();
            boolean isNoPriceType = false;
            int j = 0;
            do
            {
                if(j >= strNoPriceTypes.length)
                    break;
                if(strNoPriceTypes[j].equals(orderDetailVO.getOrderType()))
                {
                    isNoPriceType = true;
                    break;
                }
                j++;
            } while(true);
            if(isNoPriceType)
                lblPriceValue.setText("");
            else
                lblPriceValue.setText(strPrice);
            lblQualityValue.setText(strQty);
            String strBuyOrSell = orderDetailVO.getBuyOrSell();
            if(strBuyOrSell.equalsIgnoreCase("BUY"))
                lblTransactionValue.setForeground(Color.BLUE);
            else
            if(strBuyOrSell.equalsIgnoreCase("SELL"))
                lblTransactionValue.setForeground(Color.RED);
            lblTransactionValue.setText(msgConf.getUIMessages(strBuyOrSell, currentLocale));
            lblSecurityCodeValue.setText(orderDetailVO.getSymbol());
            lblFilledQtyValue.setText(StringUtil.formatQtyValue(orderDetailVO.getFilledQuantity()));
            String strNameEng = orderDetailVO.getName();
            String strNameChs = orderDetailVO.getName_chs();
            String strNameChi = orderDetailVO.getName_chi();
            if(currentLocale.equals(ClientAppConst.ZH_HK) && strNameChi != null && strNameChi.length() != 0)
                lblNameOfSecurityValue.setText(strNameChi);
            else
            if(currentLocale.equals(ClientAppConst.ZH_CN) && strNameChs != null && strNameChs.length() != 0)
                lblNameOfSecurityValue.setText(strNameChs);
            else
                lblNameOfSecurityValue.setText(strNameEng);
            tmFilledOrder.removeTableModelListener(this);
            ArrayList filledOrderist = orderDetailVO.getFilledOrderList();
            int filledOrderListSize = 0;
            if(filledOrderist == null || filledOrderist.isEmpty())
            {
                filledOrderListSize = 0;
            } else
            {
                for(int i = 0; i < filledOrderist.size(); i++)
                {
                    FilledOrderVO filledOrderVO = (FilledOrderVO)filledOrderist.get(i);
                    boolean bZeroQty = false;
                    try
                    {
                        double doubleValue = Double.parseDouble(filledOrderVO.getFilledQuantity());
                        if(doubleValue == 0.0D)
                            bZeroQty = true;
                    }
                    catch(Exception e) { }
                    if(!bZeroQty)
                        filledOrderListSize++;
                }

            }
            Object strTableData[][] = new Object[filledOrderListSize][2];
            if(filledOrderListSize > 0)
            {
                int iCurrentIndex = 0;
                for(int i = 0; i < filledOrderist.size(); i++)
                {
                    FilledOrderVO filledOrderVO = (FilledOrderVO)filledOrderist.get(i);
                    boolean bZeroQty = false;
                    try
                    {
                        double doubleValue = Double.parseDouble(filledOrderVO.getFilledQuantity());
                        if(doubleValue == 0.0D)
                            bZeroQty = true;
                    }
                    catch(Exception e) { }
                    if(!bZeroQty)
                    {
                        String strFilledPrice = StringUtil.formatPriceValue(filledOrderVO.getFilledPrice(), strCcy);
                        String strFilledQty = StringUtil.formatQtyValue(filledOrderVO.getFilledQuantity());
                        strTableData[iCurrentIndex][1] = strFilledPrice;
                        strTableData[iCurrentIndex++][0] = strFilledQty;
                    }
                }

            }
            tmFilledOrder.setData(strTableData);
            TableColumn colPrice = tblFilledOrder.getColumnModel().getColumn(0);
            TableColumn colQty = tblFilledOrder.getColumnModel().getColumn(1);
            colPrice.setPreferredWidth(orderDetailScrollPane.getViewport().getWidth() / 2);
            colQty.setPreferredWidth(orderDetailScrollPane.getViewport().getWidth() / 2);
            orderDetailScrollPane.getVerticalScrollBar().setValue(0);
            tmFilledOrder.fireTableDataChanged();
            tmFilledOrder.addTableModelListener(this);
        }
        if(currentLocale == ClientAppConst.EN_US)
            lblFilledQtyValue.setLocation(520, 153);
        else
            lblFilledQtyValue.setLocation(430, 153);
    }

    public HashMap getInputValue(String pActionType)
    {
        return null;
    }

    public boolean validate(String pActionType)
    {
        return true;
    }

    public void tableChanged(TableModelEvent tablemodelevent)
    {
    }

    public void setDefFocus()
    {
        SwingUtilities.invokeLater(new Runnable() {

            public void run()
            {
                btnBack.requestFocus();
            }
        }
);
    }

    private JTable tblFilledOrder;
    private CMTableModel tmFilledOrder;
    private JScrollPane orderDetailScrollPane;
    private JButton btnBack;
    private JLabel lbltitle;
    private JLabel lblNameOfSecurity;
    private JLabel lblNameOfSecurityValue;
    private JLabel lblSecurityCodeValue;
    private JLabel lblSecurityCode;
    private JLabel lblTransaction;
    private JLabel lblTransactionValue;
    private JLabel lblQualityValue;
    private JLabel lblQuantity;
    private JLabel lblPrice;
    private JLabel lblPriceValue;
    private JLabel lblOrderTypeValue;
    private JLabel lblOrderType;
    private JLabel lblDuration;
    private JLabel lblDurationValue;
    private JLabel lblPlaceOnValue;
    private JLabel lblPalceOn;
    private JLabel lblReference;
    private JLabel lblReferenceValue;
    private JLabel lblStatusValue;
    private JLabel lblStatus;
    private JLabel lblFilledOrderDetails;
    private JLabel lblFilledQty;
    private JLabel lblFilledQtyValue;
    private Locale currentLocale;
    private MessagesConfigurator msgConf;
    private OrderDetailVO orderDetailVO;
    private StringRenderer numericRenderer;

}
